package com.topway.dsmflex.thread.job;

import com.topway.dsmflex.Log;
import com.topway.dsmflex.model.synchro.DataFileBean;
import com.topway.dsmflex.thread.services.FileSynchroServices;

public class FileSynchroThread extends DbSynchroThread {

	private DataFileBean dt = null;
	private FileSynchroServices synchroServices = null;

	public FileSynchroThread(SynchroManager sm,DataFileBean dt)
	{
		super(sm,dt);
		this.dt = dt;
		synchroServices =new FileSynchroServices();
	}
	
	@Override
	public int SynchroData()
	{
		int _result=0;
		try {
			Log.info("正在同步表["+dt.getName()+"]");
			dt.setPageIndex(0);
			if(dt.getOperatorTarget().equals("UPDATE"))
				_result = synchroServices.synchroUpdateData(dt);
			else if(dt.getOperatorTarget().equals("INSERT"))
				_result = synchroServices.synchroInsertData(dt);
			else if(dt.getOperatorTarget().equals("INSERTUPDATE"))
				_result = synchroServices.synchroInsertOrUpdateData(dt);
			else if(dt.getOperatorTarget().equals("DELETE"))
				_result = synchroServices.synchroDeleteData(dt);
			Log.info("源表["+dt.getName()+"] 对目标表   ["+dt.getTableNameTarget()+"]  同步  ["+dt.getOperatorTarget()+"]完成，已同步["+result+"]条数据!");
		} catch (Exception e) {
			Log.error("同步表["+dt.getName()+"]发生错误，忽略!"+e.getMessage());
		}
		return _result;
	}
	
	
	
	public static void main(String[] args) {
		 
		String nterval  =String.valueOf((1000*60*0.5));
			System.out.println(nterval.indexOf(".")==-1?Long.parseLong(nterval):Long.parseLong(nterval.substring(0, nterval.indexOf("."))));
	}
	
	
}
